package com.wmvc01;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/test")
public class TestController {

  @GetMapping("/handle/exception")
  public Object exception() throws Exception {
    throw new IllegalArgumentException("异常");
  }

  @GetMapping("/echo/{info}")
  public String echo(@PathVariable(name = "info") String info, HttpServletResponse response) {
    Cookie cookie = new Cookie("wudeyun", "wudeyun");
    cookie.setHttpOnly(true);
    cookie.setMaxAge(Integer.MAX_VALUE);
    cookie.setDomain("https://www.baidu.com");
    cookie.setPath("/");
    response.addCookie(cookie);
    return "redirect:https://www.baidu.com";
  }
}
